package joindemo.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import joindemo.exception.ServiceException;
import lombok.Getter;

@Getter
public enum MessageType {

    LIKE(1,"点赞信息"),
    COLLECT(2,"收藏信息"),
    COMMENT(3,"评论信息");

    @EnumValue
    private final Integer code;
    @JsonValue
    private final String message;

    MessageType(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @JsonCreator
    public static MessageType fromCode(int code){
        for (MessageType value : MessageType.values()) {
            if (value.code == code) {
                return value;
            }
        }
        throw new ServiceException(HttpStatusEnum.ERROR);
    }

}
